// @ts-ignore
import Taro, { Component, Config } from '@tarojs/taro'
import { View, Text, Button, Image } from '@tarojs/components'
import { loginByWeixin } from '../../../api/service/user'

import './index.scss'
export default class Index extends Component{

    state = {
        loginIcon: '../../../assets/images/flow.png'
    }

    config: Config={
        navigationBarTitleText: '',
        navigationBarBackgroundColor: '#3775F6',
        // 设置为 true 则页面整体不能上下滚动
        disableScroll: true
    }
    // 登录
    handlerLogin = () => {
        // loginByWeixin().then(res => {
        //     console.log('res:', res);
            
        // });
        // 查看用户是否已授权，若已授权，则不在申请授权，则登录，获取用户信息
        Taro.getSetting({
            success: (res) => {
                console.log('res', res);
                if(res.authSetting['scope.userInfo']){
                    // 已经授权
                    // loginByWeixin().then(res => {
                    //     //console.log('res:', res);
                    // });
                    
                    // 返回前一页
                    Taro.navigateBack({delta: 1});
                }else{
                    // 申请授权获取用户信息, 再登录
                    Taro.getUserProfile({
                        desc: '用于完善会员资料', // 声明获取用户个人信息后的用途，后续会展示在弹窗中，请谨慎填写
                        success: (res) => {
                            console.log(res.userInfo);

                        }
                    });
                }
            }
        });
        //loginByWeixin();
    }

    render(){
        const { loginIcon } = this.state
        return(
            <View className='container' style='height: 100%;'>
                <View className='login-box'>
                    <View className='login-icon-cont'>
                        <Image src={loginIcon} className='login-icon'></Image>
                    </View>
                    <View className='wx-login-box'>
						<Button className='wx-login-btn' hoverClass='wx-login-btn-hover' onClick={this.handlerLogin}>
							<View className='iconfont iconai-weixin'></View>
							<Text className='login-btn-txt'>微信登录</Text>
						</Button>
					</View>
                    <View className='wx-login-footer'>
						<View className='footer-txt'>喜爱制作</View>
						<View className='footer-txt'>Copyright ©2021 天枰喜爱工作室</View>
					</View>
                </View>
            </View>
        )
    }
}
